<template>
  <el-header heigh="10%">
    <div>
      <span>盗云</span>
    </div>
    <div>
      <span class="header-name">欢迎你，{{ username }} </span>
      <el-button type="info" @click="onLogout">退出</el-button>
    </div>
  </el-header>
</template>

<script>
import { logout } from "@/api/logout.js";
export default {
  data() {
    return {
      username: this.getHeadUserName(),
    };
  },

  methods: {
    onLogout() {
      logout().then((res) => {
        localStorage.removeItem("auth_token");
        localStorage.removeItem("User");
        localStorage.removeItem("userInfo");
        this.$router.push("/login");
      });
    },

    getHeadUserName() {
      var User = JSON.parse(localStorage.getItem("User"));
      if (User.roles == "ADMIN") {
        return (this.username = "管理员");
      } else {
        return (this.username = "老师");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.el-header {
  height: 10%;
  background-color: rgb(55, 60, 65);
  display: flex;
  justify-content: space-between;
  padding-left: 50px;
  align-items: center;
  color: #fff;
  font-size: 30px;
  align-content: center;
}
.header-name {
  font-size: 20px;
}
</style>